home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / vansi.zip / NANSI_F.ASM < prev    next >
Assembly Source File  |  1989-11-22  |  25KB  |  652 lines

  1.         page    66, 132
  2. ;----- nansi_f.asm ---------------------------------------------
  3. ; The ANSI control subroutines.
  4. ; (C) 1986 Daniel Kegel, Pasadena, CA
  5. ; May be distributed for educational and personal use only
  6. ; Each routine is called with the following register usage:
  7. ;  AX = max(1, value of first parameter)
  8. ;  Z flag is set if first parameter is zero.
  9. ;  CX = number of paramters
  10. ;  SI = offset of second parameter from CS
  11. ;  DS = CS
  12. ;  ES:DI points to the current location on the memory-mapped screen.
  13. ;  DX is number of characters remaining on the current screen line.
  14. ; The control routine is free to trash AX, BX, CX, SI, and DS.
  15. ; It must preserve ES, and can alter DX and DI if it wants to move the
  16. ; cursor.
  17. ;
  18. ; Revisions:
  19. ;  19 Aug 85: Fixed horrible bug in insert/delete line.
  20. ;  26 Aug 85: Fixed simple limit-to-one-too-few-lines bug in ins/del line;
  21. ;  anyway, it inserts 24 lines when on line 2 now.  Whether it's fixed...
  22. ;  4 Sept 85: Fixed bug created on 26 Aug 85; when limiting ins/del line
  23. ;  count, we are clearing, not scrolling; fixed BIOS call to reflect this.
  24. ;  30 Jan 86: Added EGA cursor patch
  25. ;  31 Jan 86: Disabled insert/delete char in graphics modes
  26. ;             Implemented keyboard redefinition reset
  27. ;  1 Feb 86: added video_mode and max_x test after mode set
  28. ;----------------------------------------------------------------
  29.  
  30.         include nansi_d.asm
  31.  
  32.         ; To nansi_p.asm
  33.         public  ansi_fn_table
  34.  
  35.         ; From nansi.asm
  36.         extrn   port_6845:word
  37.         extrn   cur_coords:word, saved_coords:word
  38.         extrn   cur_x:byte, max_x:byte
  39.         extrn   cur_y:byte, max_y:byte
  40.         extrn   cur_attrib:byte, wrap_flag:byte
  41.         extrn   xy_to_regs:near
  42.         extrn   get_blank_attrib:near
  43.         extrn   xlate_tab_ptr:word
  44.         extrn   cpr_esc:byte, cprseq:word
  45.         extrn   video_mode:byte
  46.         extrn   lookup:near
  47.         extrn   in_g_mode:near
  48.  
  49.         ; from nansi_p.asm
  50.         extrn   param_buffer:word       ; used in keyboard programming
  51.         extrn   param_end:word
  52.         extrn   redef_end:word
  53.  
  54. keybuf  struc                           ; used in making cpr sequence
  55. len     dw      ?
  56. adr     dw      ?
  57. keybuf  ends
  58.  
  59.  
  60. ABS40   segment at 40h
  61.         org     1ah
  62. buffer_head     dw      ?       ; Used in 'flush input buffer' dos call.
  63. buffer_tail     dw      ?
  64.  
  65.         org     49h
  66. crt_mode        db      ?
  67. crt_cols        dw      ?
  68. crt_len         dw      ?
  69. crt_start       dw      ?
  70. cursor_posn     dw      8 dup (?)
  71. cursor_mode     dw      ?
  72. active_page     db      ?
  73. addr_6845       dw      ?
  74. crt_mode_set    db      ?
  75. crt_palette     db      ?
  76.  
  77.         org 84h
  78. crt_max_y       db ?            ; CJD 11/19/89 - EGA/VGA only
  79.  
  80. ABS40   ends
  81.  
  82. code    segment byte public 'CODE'
  83.         assume cs:code, ds:code
  84.  
  85. ;----- byteout ---------------------------------------------------
  86. ; Converts al to a decimal ASCII string (in 0..99),
  87. ; stores it at ES:DI++.  Returns DI pointing at byte after last digit.
  88. ; Destroys DL.
  89.  
  90. byteout proc    near
  91.         aam
  92.         add     ax, 3030h
  93.         xchg    ah, al
  94.         stosb
  95.         xchg    ah, al
  96.         stosb
  97.         ret
  98. byteout endp
  99.  
  100. ;----- ansi_fn_table -----------------------------------
  101. ; Table of offsets of terminal control subroutines in order of
  102. ; the character that invokes them, @..Z, a..z.  Exactly 53 entries.
  103. ; All the subroutines are defined below in this module.
  104. ansi_fn_table   label   word
  105.         dw      ic,  cup, cdn, cfw, cbk         ; @, A, B, C, D
  106.         dw      nul, nul, nul, hvp, nul         ; E, F, G, H, I
  107.         dw      eid, eil, il,  d_l, nul         ; J, K, L, M, N
  108.         dw      nul, dc,  nul, nul, nul         ; O, P, Q, R, S
  109.         dw      nul, nul, nul, nul, nul         ; T, U, V, W, X
  110.         dw      nul, nul                        ; Y, Z
  111.         dw      nul, nul, nul, nul, nul         ; a, b, c, d, e
  112.         dw      hvp, nul, sm,  nul, nul         ; f, g, h, i, j
  113.         dw      nul, rm,  sgr, dsr, nul         ; k, l, m, n, o
  114.         dw      key, nul, nul, scp, nul         ; p, q, r, s, t
  115.         dw      rcp, nul, nul, nul, xoc         ; u, v, w, x, y
  116.         dw      nul                             ; z
  117.  
  118. ansi_functions  proc    near            ; set return type to NEAR
  119.  
  120. ;----- nul ---------------------------------------------
  121. ; No-action ansi sequence; called when unknown command given.
  122. nul:    ret
  123.  
  124. ;----- Cursor Motion -----------------------------------------------
  125.  
  126. ;-- cursor to y,x
  127. hvp:    or      al, al          ; First parameter is desired Y coordinate.
  128.         jz      hvp_yok
  129.         dec     ax              ; Convert to zero-based coordinates.
  130. hvp_yok:mov     cur_y, al
  131.         ; Get second parameter, if it is there, and set X with it.
  132.         xor     ax, ax
  133.         cmp     cx, 2           ; was there a second parameter?
  134.         jb      hvp_xok
  135.         lodsb                   ; yes.
  136.         or      al, al
  137.         jz      hvp_xok
  138.         dec     ax              ; convert to zero-based coordinates.
  139. hvp_xok:mov     cur_x, al
  140.  
  141.         ; Clip to maximum coordinates.
  142. hvp_set:
  143.         mov     ax, cur_coords          ; al = x, ah = y
  144.         cmp     al, max_x
  145.         jbe     hvp_sxok
  146.                 mov     al, max_x
  147.                 mov     cur_x, al
  148. hvp_sxok:
  149.         cmp     ah, max_y
  150.         jbe     hvp_syok
  151.                 mov     al, max_y
  152.                 mov     cur_y, al
  153. hvp_syok:
  154.         ; Set values of DX and DI accordingly.
  155.         call    xy_to_regs
  156.         ret
  157.  
  158. ;-- cursor forward --
  159. cfw:    add     cur_x, al
  160.         jmp     hvp_set
  161.  
  162. ;-- cursor back -----
  163. cbk:    sub     cur_x, al
  164.         jae     cbk_ok
  165.                 mov     cur_x, 0
  166. cbk_ok: jmp     hvp_set
  167.  
  168. ;-- cursor down -----
  169. cdn:    add     cur_y, al
  170.         jmp     hvp_set
  171.  
  172. ;-- cursor up -------
  173. cup:    sub     cur_y, al
  174.         jae     cup_ok
  175.                 mov     cur_y, 0
  176. cup_ok: jmp     hvp_set
  177.  
  178. ;-- save cursor position --------------------------------------
  179. scp:    mov     ax, cur_coords
  180.         mov     saved_coords, ax
  181.         ret
  182.  
  183. ;-- restore cursor position -----------------------------------
  184. rcp:    mov     ax, saved_coords
  185.         mov     cur_coords, ax
  186.         jmp     hvp_set         ; Clip in case we have switched video modes.
  187.  
  188. ;-- set graphics rendition ------------------------------------
  189. ; Modifies the color in which new characters are written.
  190.  
  191. sgr:    dec     si              ; get back pointer to first parameter
  192.         or      cx, cx          ; Did he give any parameters?
  193.         jnz     sgr_loop
  194.                 mov     byte ptr [si], 0        ; no parameters, so fake
  195.                 inc     cx                      ; one with the default value.
  196.         ; For each parameter
  197. sgr_loop:
  198.                 lodsb                           ; al = next parameter
  199.                 ; Search color table
  200.                 push    cx
  201.                 mov     cx, colors
  202.                 mov     bx, offset color_table-3
  203. sgr_search:
  204.                         add     bx, 3
  205.                         cmp     al, byte ptr [bx]
  206.                         loopnz  sgr_search      ; until match found or done
  207.                 jnz     sgr_loopx
  208.  
  209.                 ; If parameter named a known color, set the current
  210.                 ; color variable.
  211.                 mov     ax, [bx+1]
  212.                 and     cur_attrib, al
  213.                 or      cur_attrib, ah
  214. sgr_loopx:
  215.                 pop     cx
  216.                 loop    sgr_loop                ; until no more parameters.
  217.         ret
  218.  
  219. ;-- erase in line ----------------------------------------
  220. ; Uses BIOS to scroll away a one-line rectangle
  221. eil:    push    dx
  222.         mov     cx, cur_coords
  223.         mov     dh, ch
  224.         jmp     short scrollem
  225.  
  226. ;-- erase in display -------------------------------------
  227. ; Uses BIOS to scroll away all of display
  228. eid:    cmp     al, 2
  229.         jnz     eid_ignore      ; param must be two
  230.         if      cls_homes_too
  231.                 mov     cur_coords, 0
  232.                 call    xy_to_re